<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Img extends wsFrontend
{
    public function __construct()
    {
        parent::__construct();
        if (strpos(strtolower($this->uri->uri_string()), 'img') !== false) {
            redirect(base_url());
        }
        $this->db->cache_set_path(dirname($this->db->cachedir) . '/wallpaper_page/');
    }

    public function index()
    {
        $img = $this->input->get('img');
        if (preg_match('/.*-(.*)-\d+x\d+-.*-\d+\..*/', $img, $regs)) {
            $this->load->model('wallpaper_model');
            $wallpaper = $this->wallpaper_model->getWallpaperByHASH($regs[1]);
            if (!$wallpaper)
                redirect();
            $search_replace = array(
                '{C_SLUG_FULL}' => $wallpaper->cFullSlug,
                '{C_SLUG}' => $wallpaper->category_slug,
                '{W_SLUG}' => $wallpaper->wallpaper_slug,
                '{W_HASH}' => $wallpaper->wallpaper_hash
            );
            redirect($this->route_links->build_link('wallpaper_page', $search_replace));
        } else
            redirect();
    }
}
